import { createRouter, RouteRecordRaw, createWebHashHistory } from 'vue-router';
import { beforeEach, afterEach } from './routerGuards.ts'; // 引入路由守卫

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/login/login',
    component: () => import('@/layout/index.vue'),
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/home/index.vue'),
      meta: {
        title: '首页'
      }
    },
    {
      path: '/login/:path',
      name: 'login',
      component: () => import('@/views/login/index.vue'),
      meta: {
        title: '登录',
      },
    },
    {
      path: '/reservePage',
      name: 'reservePage',
      component: () => import('@/views/reservePage/index.vue'),
      meta: {
        title: '心理预约'
      },
    },
    {
      path: '/articlePage/details',
      name: 'articleDetail',
      component: () => import('@/views/articlePage/components/details.vue'),
      meta: {
        title: '文章详情'
      },
    },
    {
      path: '/client/:path',
      name: 'clientSettings',
      component: () => import('@/views/personalSettings/client/index.vue'),
      meta: { requiresAuth: true, userType: 1 }
    },
    {
      path: '/counselor/:path',
      name: 'counselorSettings',
      component: () => import('@/views/personalSettings/counselor/index.vue'),
      meta: { requiresAuth: true, userType: 2 ,title: '咨询师个人设置'}
    },
    {
      path: '/articlePage',
      name: 'articlePage',
      component: () => import('@/views/articlePage/index.vue'),
      meta: {
        title: '文章目录'
      },
    },
    {
      path: '/articlePage/:id',
      name: 'articleDetail',
      component: () => import('@/views/articlePage/components/details.vue'),
      meta: {
        title: '文章详情'
      },
    },
    {
      path: '/noticePage/:id',
      name: 'noticeDetail',
      component: () => import('@/views/noticePage/components/details.vue'),
      meta: {
        title: '公告详情'
      },
    },
    {
      path: '/noticePage',
      name: 'noticePage',
      component: () => import('@/views/noticePage/index.vue'),
      meta: {
        title: '公告目录'
      },
    },
    {
      path: '/reservePage/:id',
      name: 'reserveDetail',
      component: () => import('@/views/reservePage/components/details.vue'),
      meta: {
        title: '咨询师详情'
      },
    },
    {
      path: '/reservePage/details/timechoose',
      name: 'timechoose',
      component: () => import('@/views/reservePage/components/timeChoose.vue'),
      meta: {
        title: '预约时间'
      },
    }
    ]
  },
  // 根据需要添加更多的路由
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});


router.beforeEach(beforeEach);
router.afterEach(afterEach);

export default router;